import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "path";
import { componentTagger } from "lovable-tagger";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
  server: {
    host: "::",
    port: 8088,
    proxy: {
      // 开发环境代理配置
      "/videoanalysis": {
        target: "http://127.0.0.1:8080", // 后端API地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/videoanalysis/, ""),
        // 可选：添加WebSocket支持
        ws: true,
        // 可选：添加安全证书验证绕过（仅开发环境）
        secure: false,
      },
    },
  },
  build: {
    outDir: "build", // 将打包后的文件输出到 build 目录
  },
  plugins: [react(), mode === "development" && componentTagger()].filter(
    Boolean
  ),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  optimizeDeps: {
    esbuildOptions: {
      target: "es2020", // 或者你需要的目标语法版本
    },
  },
  esbuild: {
    target: "es2020", // 确保 ESBuild 也使用相同的目标
  },
}));
